package com.angle3d;

import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;

/**
 * Class representing a 3D view. This class extends the Android GLSurfaceView class, which supports OpenGL ES rendering.
 * @author Alessandro Boccalatte
 *
 */
public class View3D extends GLSurfaceView {

	private final SceneRenderer mRenderer;
	private final Camera mCamera = new Camera();
	
	private Node mScene = null;
	
	/**
	 * Creates a view with an associated Context.
	 * @param context
	 */
	public View3D(Context context) {
		super(context);
		
		// Create an OpenGL ES 2.0 context.
        setEGLContextClientVersion(2);
        setEGLConfigChooser(8, 8, 8, 8, 16, 0);

		mRenderer = new SceneRenderer(this);	
		setRenderer(mRenderer);
		
        getHolder().setFormat(PixelFormat.TRANSLUCENT);
	}
	
	/**
	 * Returns the camera of this view.
	 * @return the view camera.
	 * @see {@link Camera}
	 */
	public Camera getCamera() {
		return mCamera;
	}
	
	/**
	 * Sets the root Node of the scene to be rendered.
	 * @param scene the root Node of the scene.
	 * @see #getScene()
	 */
	public void setScene(Node scene) {
		mScene = scene;
	}
	
	/**
	 * Returns the root Node of the scene.
	 * @return the root Node of the scene.
	 * @see #setScene(Node)
	 */
	public Node getScene() {
		return mScene;
	}
	
	/**
	 * Sets the clear color of the OpenGL view.
	 * @param r red component
	 * @param g green component
	 * @param b blue component
	 * @param a alpha component
	 */
	public void setClearColor(float r, float g, float b, float a) {
		mRenderer.setClearColor(r, g, b, a);
	}
}


